package hn.cch.server;

import hn.cch.commom.EchoCommon;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Date;

public class EchoServer extends UnicastRemoteObject implements EchoCommon {


    protected EchoServer() throws RemoteException {
    }

    public String echoString(String string) throws Exception {
        String result = new Date().toString() + "->" + string;
        System.out.println(result);
        return result;
    }


    public static void main(String[] args) {

        try {

            EchoCommon echoCommon = new EchoServer();


            Registry registry = LocateRegistry.createRegistry(8808);

            //Registry实现
            // registry.rebind("echo", echoCommon);

            //Naming实现
            String string = "rmi://0.0.0.0:8808/echo";
            Naming.rebind(string, echoCommon);


            System.out.println("EchoServer rebind 8808/echo ");

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
